{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "### Modern machine learning methods <br>for trustworthy science\n",
    "\n",
    "Tom Charnock\n",
    "\n",
    "Institut d'Astrophysique de Paris\n",
    "<br><br><br>\n",
    "\n",
    "<div class=\"row\">\n",
    "    <div style=\"float: left; width: 20%; padding-right: 70px; padding-top:35px\">\n",
    "        <img src=\"../figures/SU.png\" alt=\"Sorbonne Université\" style=\"width:80%;\"/>\n",
    "    </div>\n",
    "    <div style=\"float: left; width: 20%; padding: 0px;\">\n",
    "        <img src=\"../figures/ANR.png\" alt=\"ANR\" style=\"width:40%;\"/>\n",
    "    </div>\n",
    "    <div style=\"float: left; width: 20%; padding: 5px;\">\n",
    "        <img src=\"../figures/IAP.png\" alt=\"IAP\" style=\"width:40%;\"/>\n",
    "    </div>\n",
    "    <div style=\"float: left; width: 20%; padding: 5px;\">\n",
    "        <img src=\"../figures/CNRS.png\" alt=\"CNRS\" style=\"width:30%;\"/>\n",
    "    </div>\n",
    "    <div style=\"float: left; width: 20%; padding: 5px;\">\n",
    "        <img src=\"../figures/Aquila.png\" alt=\"Aquila\" style=\"width:60%;\"/>\n",
    "    </div>\n",
    "</div> "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### Why neural networks don't work <br>(and how to use them)\n",
    "\n",
    "Tom Charnock\n",
    "\n",
    "Institut d'Astrophysique de Paris\n",
    "<br><br><br>\n",
    "\n",
    "<div class=\"row\">\n",
    "    <div style=\"float: left; width: 20%; padding-right: 70px; padding-top:35px\">\n",
    "        <img src=\"../figures/SU.png\" alt=\"Sorbonne Université\" style=\"width:80%;\"/>\n",
    "    </div>\n",
    "    <div style=\"float: left; width: 20%; padding: 0px;\">\n",
    "        <img src=\"../figures/ANR.png\" alt=\"ANR\" style=\"width:40%;\"/>\n",
    "    </div>\n",
    "    <div style=\"float: left; width: 20%; padding: 5px;\">\n",
    "        <img src=\"../figures/IAP.png\" alt=\"IAP\" style=\"width:40%;\"/>\n",
    "    </div>\n",
    "    <div style=\"float: left; width: 20%; padding: 5px;\">\n",
    "        <img src=\"../figures/CNRS.png\" alt=\"CNRS\" style=\"width:30%;\"/>\n",
    "    </div>\n",
    "    <div style=\"float: left; width: 20%; padding: 5px;\">\n",
    "        <img src=\"../figures/Aquila.png\" alt=\"Aquila\" style=\"width:60%;\"/>\n",
    "    </div>\n",
    "</div> "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### Why neural networks don't work<br><br>\n",
    "\n",
    "Tom Charnock\n",
    "\n",
    "Institut d'Astrophysique de Paris\n",
    "<br><br><br>\n",
    "\n",
    "<div class=\"row\">\n",
    "    <div style=\"float: left; width: 20%; padding-right: 70px; padding-top:35px\">\n",
    "        <img src=\"../figures/SU.png\" alt=\"Sorbonne Université\" style=\"width:80%;\"/>\n",
    "    </div>\n",
    "    <div style=\"float: left; width: 20%; padding: 0px;\">\n",
    "        <img src=\"../figures/ANR.png\" alt=\"ANR\" style=\"width:40%;\"/>\n",
    "    </div>\n",
    "    <div style=\"float: left; width: 20%; padding: 5px;\">\n",
    "        <img src=\"../figures/IAP.png\" alt=\"IAP\" style=\"width:40%;\"/>\n",
    "    </div>\n",
    "    <div style=\"float: left; width: 20%; padding: 5px;\">\n",
    "        <img src=\"../figures/CNRS.png\" alt=\"CNRS\" style=\"width:30%;\"/>\n",
    "    </div>\n",
    "    <div style=\"float: left; width: 20%; padding: 5px;\">\n",
    "        <img src=\"../figures/Aquila.png\" alt=\"Aquila\" style=\"width:60%;\"/>\n",
    "    </div>\n",
    "</div> "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Apologies about the term bias\n",
    "\n",
    "- when something is intrinsically unknowable it is biased\n",
    "\n",
    "- if there is some offset, which could in principle be corrected, it is biased"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "### I (almost always) mean the top one"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "<img style=\"max-width:65%;max-height:60%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/neural_network_t.svg\">\n",
    "<br>\n",
    "<center>\n",
    "$$\\mathbb{NN}(\\boldsymbol{\\omega},\\boldsymbol{\\alpha}) : {\\bf d}\\rightarrow\\boldsymbol{\\tau}$$\n",
    "An approximation to a model, $\\mathcal{M} : {\\bf d}\\rightarrow{\\bf t}$\n",
    "</center>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## A crazy likelihood surface of how likely we are to get targets from data\n",
    "<img style=\"max-width:65%;max-height:60%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/likelihood_t.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## What are we actually interested in?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "$$\\mathcal{P}({\\bf t}|{\\bf d}) = \\int d\\boldsymbol{\\omega}d\\boldsymbol{\\alpha}~\\mathcal{L}({\\bf t}|{\\bf d},\\boldsymbol{\\omega},\\boldsymbol{\\alpha})\\mathcal{P}(\\boldsymbol{\\omega},\\boldsymbol{\\alpha})$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "<div style=\"float:left;width:45%\">\n",
    "    $\\mathcal{P}({\\bf t}|{\\bf d})$ - <u>Posterior predictive density</u><br>\n",
    "    How likely are the true targets given some data?<br><br>\n",
    "</div>\n",
    "<div style=\"float:left;width:10%\"><br></div>\n",
    "<div style=\"float:left;width:45%\">\n",
    "    $\\mathcal{L}({\\bf t}|{\\bf d},\\boldsymbol{\\omega},\\boldsymbol{\\alpha})$ - <u>Likelihood</u><br>\n",
    "    How likely are the targets to be generated by a particular network?\n",
    "</div>\n",
    "<div style=\"float:left;width:100%\">\n",
    "    $\\mathcal{P}(\\boldsymbol{\\omega},\\boldsymbol{\\alpha})$ - <u>Probability density</u><br>\n",
    "    What is the probability of obtaining a particular network with particular parameter values?\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "$$\\mathcal{P}({\\bf t}|{\\bf d})= \\int d\\boldsymbol{\\omega}d\\boldsymbol{\\alpha}~\\mathcal{L}({\\bf t}|{\\bf d},\\boldsymbol{\\omega},\\boldsymbol{\\alpha})\\mathcal{P}(\\boldsymbol{\\omega},\\boldsymbol{\\alpha})$$\n",
    "<br><br><br>\n",
    "<img style=\"max-width:100%;max-height:50%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/posterior_predictive_t.gif\">\n",
    "<br>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Where does this information about the weights and hyperparameters come from?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### Training and validation data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "Training data and targets: $\\small\\boldsymbol{\\{}{\\bf d},{\\bf t}\\boldsymbol{\\}}^\\textrm{train}\\equiv\\{{\\bf d}^\\textrm{train}_i, {\\bf t}^\\textrm{train}_i|i\\in[1,n_\\textrm{train}]\\}$<br><br>\n",
    "Validation data and targets: $\\small\\boldsymbol{\\{}{\\bf d},{\\bf t}\\boldsymbol{\\}}^\\textrm{val}\\equiv\\small\\{{\\bf d}^\\textrm{val}_i, {\\bf t}^\\textrm{val}_i|i\\in[1,n_\\textrm{val}]\\}$\n",
    "#### Posterior distribution of weights and hyperparameters\n",
    "$$\\begin{align*}\n",
    "    &\\small\\mathcal{P}(\\boldsymbol{\\omega},\\boldsymbol{\\alpha}|\\boldsymbol{\\{}{\\bf d},{\\bf t}\\boldsymbol{\\}}^\\textrm{train},\\boldsymbol{\\{}{\\bf d},{\\bf t}\\boldsymbol{\\}}^\\textrm{val})\\propto\\\\\n",
    "    &\\small\\phantom{hello}\\mathcal{L}(\\boldsymbol{\\omega},\\boldsymbol{\\alpha}|\\boldsymbol{\\{}{\\bf d},{\\bf t}\\boldsymbol{\\}}^\\textrm{train},\\boldsymbol{\\{}{\\bf d},{\\bf t}\\boldsymbol{\\}}^\\textrm{val})p(\\boldsymbol{\\omega},\\boldsymbol{\\alpha})\n",
    "\\end{align*}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## The failing of traditional training"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "<img style=\"max-width:90%;max-height:50%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/Flat_likelihood_t.svg\">\n",
    "<div style=\"float:left;width:50%\"><br>\n",
    "    $\\mathcal{M} : {\\bf d} \\to {\\bf t}$ <b> approximator</b><br>\n",
    "    $$\\mathbb{NN}(\\boldsymbol{\\omega}, \\boldsymbol{\\alpha}) : {\\bf d}\\to\\boldsymbol{\\tau}$$<br>\n",
    "    <b>Cost function and likelihood</b>\n",
    "    $$\\boldsymbol{\\Lambda}({\\bf t}, \\boldsymbol{\\tau}) = -\\ln\\mathcal{L}({\\bf t}|{\\bf d},\\boldsymbol{\\omega}^*,\\boldsymbol{\\alpha}^*)$$\n",
    "</div>\n",
    "<div style=\"float:left;width:10%\"><br></div>\n",
    "<div style=\"float:left;width:40%\">\n",
    "<br>    <center>\n",
    "    $\\boldsymbol{\\Lambda}({\\bf t},\\boldsymbol{\\tau})$<br>smooth and convex<br><br>\n",
    "    $\\mathcal{L}({\\bf t}|{\\bf d},\\boldsymbol{\\omega},\\boldsymbol{\\alpha})$<br>complex and non-convex in $\\boldsymbol{\\omega}$ and $\\boldsymbol{\\alpha}$\n",
    "    </center>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Optimising (or training) a network"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "#### What are the maximum likelihood estimates of the weights?\n",
    "<br>\n",
    "<img style=\"max-width:80%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/mle_net.gif\">\n",
    "\n",
    "$$\\boldsymbol{\\omega}^\\textrm{MLE}=\\underset{\\boldsymbol{\\omega}}{\\textrm{argmax}}\\left[\\mathcal{L}(\\boldsymbol{\\{}{\\bf t}\\boldsymbol{\\}}^\\textrm{train}|\\boldsymbol{\\{}{\\bf d}\\boldsymbol{\\}}^\\textrm{train}, \\boldsymbol{\\omega}, \\boldsymbol{\\alpha}^*)\\right]$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### Local maximum likelihood estimates\n",
    "<br>\n",
    "<img style=\"max-width:80%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/wrong_maxima_t.gif\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## The main problem..."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## We degenerate the posterior\n",
    "<br>\n",
    "$$\\begin{align*}\n",
    "    \\mathcal{P}(\\boldsymbol{\\omega},\\boldsymbol{\\alpha}|\\boldsymbol{\\{}{\\bf d},{\\bf t}\\boldsymbol{\\}}^\\textrm{train})\\propto&~\\mathcal{L}(\\boldsymbol{\\omega},\\boldsymbol{\\alpha}|\\boldsymbol{\\{}{\\bf d},{\\bf t}\\boldsymbol{\\}}^\\textrm{train})p(\\boldsymbol{\\omega},\\boldsymbol{\\alpha})\\\\\n",
    "    \\to&~\\delta(\\boldsymbol{\\omega}-\\boldsymbol{\\omega}^\\textrm{MLE},\\boldsymbol{\\alpha}-\\boldsymbol{\\alpha}^*)\n",
    "\\end{align*}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "<img style=\"max-width:100%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/posterior_predictive_mle_t.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### All predictions are (probably incorrect) estimates<br><br>\n",
    "<img style=\"max-width:70%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/nn_b_t.gif\"><br>\n",
    "$$\\mathcal{P}({\\bf t}|{\\bf d})=\\delta(\\boldsymbol{\\tau})$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "### There is no way to interpret how close $\\boldsymbol{\\tau}$ is to ${\\bf t}$..."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "### Because the likelihood is non-interpretably complex"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Are there better methods?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Variational inference\n",
    "<img style=\"max-width:80%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/VB_t.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "$$\\small\\mathcal{P}({\\bf t}|{\\bf d})=\\int d\\boldsymbol{\\omega}d\\boldsymbol{\\nu}d\\boldsymbol{\\alpha}~\\mathcal{L}({\\bf t}|{\\bf d},\\boldsymbol{\\omega},\\boldsymbol{\\alpha})\\mathcal{Q}(\\boldsymbol{\\omega}|\\boldsymbol{\\nu}, \\boldsymbol{\\alpha}, \\boldsymbol{\\{}{\\bf d}, {\\bf t}\\boldsymbol{\\}}^\\textrm{train})p(\\boldsymbol{\\nu},\\boldsymbol{\\alpha})$$\n",
    "<br>\n",
    "<img style=\"max-width:80%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/vi_b_t.gif\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "#### Still depends on fixed weights in the complex likelihood surface<br> and choice of variational distribution\n",
    "<br>\n",
    "<img style=\"max-width:110%;max-height:70%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/wrong_variational.svg\">\n",
    "$$\\begin{align*}\n",
    "\\mathcal{P}({\\bf t}|{\\bf d})&=\\int d\\boldsymbol{\\omega}d\\boldsymbol{\\nu}d\\boldsymbol{\\alpha}~\\mathcal{L}({\\bf t}|{\\bf d},\\boldsymbol{\\omega},\\boldsymbol{\\alpha})\\mathcal{Q}(\\boldsymbol{\\omega}|\\boldsymbol{\\nu}, \\boldsymbol{\\alpha}, \\boldsymbol{\\{}{\\bf d}, {\\bf t}\\boldsymbol{\\}}^\\textrm{train})\\\\\n",
    "&\\phantom{hellohello}\\times\\delta(\\boldsymbol{\\nu}-\\boldsymbol{\\nu}^\\textrm{MLE}, \\boldsymbol{\\alpha}-\\boldsymbol{\\alpha}^*)\\\\\n",
    "&=\\int d\\boldsymbol{\\omega}~\\mathcal{L}({\\bf t}|{\\bf d},\\boldsymbol{\\omega}, \\boldsymbol{\\alpha}^*)\\mathcal{Q}(\\boldsymbol{\\omega}|\\boldsymbol{\\nu}^\\textrm{MLE}, \\boldsymbol{\\alpha}^*, \\boldsymbol{\\{}{\\bf d}, {\\bf t}\\boldsymbol{\\}}^\\textrm{train}).\n",
    "\\end{align*}$$"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "# Bayesian neural networks"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "<img style=\"max-width:80%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/Bayes_t.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "$$\\begin{align*}\n",
    "\\small\\mathcal{P}({\\bf t}|{\\bf d}) =&\\small~\\int d\\boldsymbol{\\omega}d\\boldsymbol{\\alpha}~\\mathcal{L}({\\bf t}|{\\bf d}, \\boldsymbol{\\omega}, \\boldsymbol{\\alpha})\\mathcal{P}(\\boldsymbol{\\omega},\\boldsymbol{\\alpha}|\\boldsymbol{\\{}{\\bf d}, {\\bf t}\\boldsymbol{\\}}^\\textrm{train})\\\\\n",
    " \\propto&~\\int d\\boldsymbol{\\omega}d\\boldsymbol{\\alpha}~\\mathcal{L}({\\bf t}|{\\bf d}, \\boldsymbol{\\omega}, \\boldsymbol{\\alpha})\\\\\n",
    " &\\phantom{hello}\\times \\prod_i^{n_\\textrm{train}}\\mathcal{L}({\\bf t}^\\textrm{train}_i|{\\bf d}_i^\\textrm{train}, \\boldsymbol{\\omega},\\boldsymbol{\\alpha})p(\\boldsymbol{\\omega},\\boldsymbol{\\alpha}).\\phantom{hello}\n",
    "\\end{align*}\n",
    "$$\n",
    "\n",
    "### Sample the likelihood of the training data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "# Still dependent on the training data!\n",
    "\n",
    "<br>\n",
    "\n",
    "Classical network : $\\tiny \\mathcal{P}(\\boldsymbol{\\omega},\\boldsymbol{\\alpha}|\\boldsymbol{\\{}{\\bf d},{\\bf t}\\boldsymbol{\\}}^\\textrm{train}) \\to \\delta(\\boldsymbol{\\omega}-\\boldsymbol{\\omega}^\\textrm{MLE},\\boldsymbol{\\alpha}-\\boldsymbol{\\alpha}^*)$\n",
    "\n",
    "Variational inference : $\\tiny \\mathcal{P}(\\boldsymbol{\\omega},\\boldsymbol{\\alpha}|\\boldsymbol{\\{}{\\bf d},{\\bf t}\\boldsymbol{\\}}^\\textrm{train}) = \\mathcal{Q}(\\boldsymbol{\\omega}|\\boldsymbol{\\nu}^\\textrm{MLE}, \\boldsymbol{\\alpha}^*, \\boldsymbol{\\{}{\\bf d},{\\bf t}\\boldsymbol{\\}}^\\textrm{train})$\n",
    "\n",
    "Bayesian networks : $\\tiny \\mathcal{P}(\\boldsymbol{\\omega},\\boldsymbol{\\alpha}|\\boldsymbol{\\{}{\\bf d},{\\bf t}\\boldsymbol{\\}}^\\textrm{train}) =\\prod_i^{n_\\textrm{train}}\\mathcal{L}({\\bf t}^\\textrm{train}_i|{\\bf d}^\\textrm{train}_i,\\boldsymbol{\\omega},\\boldsymbol{\\alpha})p(\\boldsymbol{\\omega},\\boldsymbol{\\alpha})$\n",
    "\n",
    "<img style=\"max-width:80%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/posterior_predictive_wrong_t.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Problems with physical models..."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "<img style=\"max-width:65%;max-height:60%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/nn_b_t.gif\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## How can we use a neural network then?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "## Build it into the physical model"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Method 1 : <br><br>Infer the data, physics and the neural network"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "<img style=\"max-width:80%;max-height:60%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/NBM_square.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## Method 2 :<br><br>Understand the likelihood (using neural physical engines)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "<div style=\"float:left;width:45%\">\n",
    "    <img style=\"max-width:100%;max-height:100%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/convolutional_network.svg\">\n",
    "</div>\n",
    "<div style=\"float:left;width:10%\"><br></div> \n",
    "<div style=\"float:left;width:45%\">\n",
    "    <img style=\"max-width:100%;max-height:100%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/spherical_convolutional_network.svg\"><br><br>\n",
    "</div>\n",
    "<div style=\"float:left;width:45%\">\n",
    "    <img style=\"max-width:100%;max-height:100%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/receptive_field.svg\">\n",
    "</div>\n",
    "<div style=\"float:left;width:10%\"><br></div>\n",
    "<div style=\"float:left;width:45%\">\n",
    "    <img style=\"max-width:100%;max-height:100%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/kernels.svg\">\n",
    "</div><br>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Method 3 : <br><br>Likelihood-free inference"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "<img style=\"max-width:100%;max-height:60%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/physical_model_nn.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "subslide"
    }
   },
   "source": [
    "<b>Compare distance between observed summaries and simulation summaries and select results within $\\epsilon$</b><br><br>\n",
    "<img style=\"max-width:70%;max-height:70%;display:block;height:auto;margin:auto;float:none!important;\" src=\"../figures/ABC_IMNN.svg\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "# Conclusions"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "fragment"
    }
   },
   "source": [
    "### Neural networks are not to be trusted\n",
    "\n",
    "### They can make trusty companions - when the correct framework is introduced\n",
    "\n",
    "### Using statistics we can build neural networks into the forward model to get unbiased results"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "slideshow": {
     "slide_type": "slide"
    }
   },
   "source": [
    "## For more information read my new blog<br><br>\n",
    "\n",
    "<center>\n",
    "    <a href=\"bit.ly/ProbNN\">bit.ly/ProbNN</a>\n",
    "</center>\n"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Diaporama",
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  },
  "rise": {
   "leap_motion": {
    "naturalSwipe": true,
    "pointerColor": "#d80000",
    "pointerOpacity": 0.5
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
